package com.mvs.sillybat;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;

public class MainMenuScreen extends ScreenAdapter {
	SillyBat game;
	OrthographicCamera guiCam,textcam;
	Rectangle soundBounds;
	Rectangle playBounds;
	Rectangle highscoresBounds;
	Rectangle helpBounds;
	Vector3 touchPoint;
	static final float SCREEN_WIDTH = 10;
	static final float SCREEN_HEIGHT = 15;

	public MainMenuScreen(SillyBat game) {
		this.game = game;

		textcam = new OrthographicCamera(480, 800);
		textcam.position.set(480 / 2, 800 / 2, 0);
		guiCam = new OrthographicCamera(SCREEN_WIDTH, SCREEN_HEIGHT);
		guiCam.position.set(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 0);
		guiCam.update();
		playBounds = new Rectangle(3f ,6.5f,4,1.5f);
		// highscoresBounds = new Rectangle(160 - 150, 200 - 18, 300, 36);
		// helpBounds = new Rectangle(160 - 150, 200 - 18 - 36, 300, 36);
		touchPoint = new Vector3();
	}

	public void update() {
		if (Gdx.input.justTouched()) {
			guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(),
					0));

			if (playBounds.contains(touchPoint.x, touchPoint.y)) {
				Assets.playSound(Assets.clickSound);
				game.setScreen(new GameScreen(game));
				return;
			}
			// if (highscoresBounds.contains(touchPoint.x, touchPoint.y)) {
			// Assets.playSound(Assets.clickSound);
			// game.setScreen(new HighscoresScreen(game));
			// return;
			// }
			// if (helpBounds.contains(touchPoint.x, touchPoint.y)) {
			// Assets.playSound(Assets.clickSound);
			// game.setScreen(new HelpScreen(game));
			// return;
			// }
			// if (soundBounds.contains(touchPoint.x, touchPoint.y)) {
			// Assets.playSound(Assets.clickSound);
			// Settings.soundEnabled = !Settings.soundEnabled;
			// if (Settings.soundEnabled)
			// Assets.music.play();
			// else
			// Assets.music.pause();
			// }
		}
	}

	public void draw() {
		GL20 gl = Gdx.gl;
		gl.glClearColor(1, 0, 0, 1);
		gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		guiCam.update();
		game.batch.setProjectionMatrix(guiCam.combined);

		game.batch.disableBlending();
		game.batch.begin();
		game.batch.draw(Assets.backgroundRegion, guiCam.position.x - SCREEN_WIDTH / 2,
				guiCam.position.y - SCREEN_HEIGHT / 2, SCREEN_WIDTH,
				SCREEN_HEIGHT);
		//game.font.draw(game.batch, "Flying Bot v0.1",1, 1);
		game.batch.end();

		game.batch.enableBlending();
		game.batch.begin();
		
		//game.batch.draw(Assets.logo, Gdx.graphics.getWidth()/2- Assets.logo.getRegionWidth()/1.4f, Gdx.graphics.getHeight()- Assets.logo.getRegionHeight()/0.75f ,Gdx.graphics.getWidth()*4/5,Gdx.graphics.getHeight()/3);
		game.batch.draw(Assets.logo, 1,9.5f,8,5 );
	//	game.batch.draw(Assets.Bot2, 0,2f,6f,7 );
		//Gdx.app.log("MyTag", "guicam x"+guiCam.position.x );
		game.batch.draw(Assets.play,3f ,6.5f,4,1.5f);
		game.batch.draw(Assets.highscore,1f ,4.75f,8,1.5f);
		game.batch.draw(Assets.help,3f ,3f,4,1.5f);
		// game.batch.draw(Settings.soundEnabled ? Assets.soundOn :
		// Assets.soundOff, 0, 0, 64, 64);
		game.batch.end();
		
		textcam.update();
		game.batch.setProjectionMatrix(textcam.combined);
		game.batch.begin();
		
		game.font.draw(game.batch, "Flying Bot v0.1",10, 790);
		game.batch.end();
	}

	@Override
	public void render(float delta) {
		update();
		draw();
	}

	@Override
	public void pause() {
		// Settings.save();
	}
}
